// pages/city/city.js
import {
  req
} from '../../http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cityData: [],
    sortCity: [],
    windowHeight:"",
    windowWidth:"",
    pixelRatio:"",
    // 当前选择的导航字母
    selected: 0,
    // 选择字母视图滚动的位置id
    scrollIntoView: 'A',
    eachLetterHeight:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.request({
      url: 'https://api-m.mtime.cn/Showtime/HotCitiesByCinema.api',
      data: '',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        let arr = res.data.p;
        arr.sort(function(a, b) {
          if (a.pinyinFull > b.pinyinFull) {
            return 1;
          } else if (a.pinyinFull < b.pinyinFull) {
            return -1;
          } else {
            return 0;
          }
        });

        arr.map(x => {
          x['k'] = x.pinyinFull.substr(0, 1).toUpperCase();
          return x;
        })

        let page_obj = {};
        arr.forEach(el => {
          if (page_obj[el.k]) {
            page_obj[el.k].push(el);
          } else {
            page_obj[el.k] = [el];
          }
        })
        console.log('987', page_obj);
        that.setData({
          cityData: page_obj
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
    this.slideCity();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  slideCity(){
    const res = wx.getSystemInfoSync()
    this.setData({
      windowHeight: res.windowHeight,
      windowWidth: res.windowWidth,
      pixelRatio: res.pixelRatio
    });
    const navHeight = this.data.windowHeight * 0.94;
    eachLetterHeight = navHeight / 26,
    comTop = (this.data.windowHeight - navHeight) / 2,
    temp = [];
    this.setData({
      eachLetterHeight: eachLetterHeight
    });
    console.log(eachLetterHeight)
    
  }
})